<?php
/**
 * @package		Joomla.Administrator
 * @subpackage	com_weblinks
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');

$user		= JFactory::getUser();
$userId		= $user->get('id');
$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));
$canOrder	= $user->authorise('core.edit.state', 'com_congregation');
$saveOrder	= $listOrder == 'a.ordering';

?>

<form action="<?php echo JRoute::_('index.php?option=com_congregation&view=provinces'); ?>" method="post" name="adminForm">
<div id="editcell">
	<table class="adminlist">
	<thead>
		<tr>
			<th width="5">
				<?php echo JText::_( 'ID' ); ?>
			</th>
			<th width="20">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
			</th>			
			<th width="50%">
				<?php echo JText::_( 'Province Name' ); ?>
			</th>
			<th width="80">
				<?php echo JText::_( 'Ordering' ); ?>
			<?php echo JHTML::_('grid.order', $this->items); ?>
			</th>
			<th>
				<?php echo JText::_( 'Communities' ); ?>
			</th>
		</tr>
	</thead>
	<?php
	$k = 0;
	if(count($this->items) > 0):
			foreach ($this->items as $i => $item) :
			//$ordering	= ($listOrder == 'a.ordering');
			$ordering = true;
			$canCreate	= $user->authorise('core.create',		'com_congregation.province.'.$item->p_id);
			$canEdit	= $user->authorise('core.edit',			'com_congregation.province.'.$item->p_id);
			$canChange	= $user->authorise('core.edit.state',	'com_congregation.province.'.$item->p_id);
		
		?>
		<tr class='<?php echo "row$k"; ?>'>
			<td>
				<?php echo $item->p_id; ?>
			</td>
			<td>
				<?php echo JHtml::_('grid.id', $i, $item->p_id); ?>
			</td>
			<td>
				<a href='<?php echo JRoute::_('index.php?option=com_congregation&task=province.edit&p_id='.(int) $item->p_id); ?>'>
				<?php echo $item->p_name ; ?>
				</a>
			</td>
			<td class="order">
				<?php if ($canChange) : ?>
					<?php /* if ($saveOrder) :*/?>
						<?php if ($listDirn == 'asc') : ?>
							<span><?php echo $this->pagination->orderUpIcon($i, true, 'province.orderup', 'JLIB_HTML_MOVE_UP', $ordering); ?></span>
							<span><?php echo $this->pagination->orderDownIcon($i, $this->pagination->total, true, 'province.orderdown', 'JLIB_HTML_MOVE_DOWN', $ordering); ?></span>
						<?php elseif ($listDirn == 'desc') : ?>
							<span><?php echo $this->pagination->orderUpIcon($i, true, 'province.orderdown', 'JLIB_HTML_MOVE_UP', $ordering); ?></span>
							<span><?php echo $this->pagination->orderDownIcon($i, $this->pagination->total, true, 'province.orderup', 'JLIB_HTML_MOVE_DOWN', $ordering); ?></span>
						<?php endif; ?>
					<?php /* endif;*/ ?>
					<?php $disabled = $saveOrder ?  '' : 'disabled="disabled"'; ?>
					<input type="text" name="order[]" size="5" value="<?php echo $item->ordering;?>" <?php echo $disabled ?> class="text-area-order" />
				<?php else : ?>
					<?php echo $item->ordering; ?>
				<?php endif; ?>
			</td>
			<td>
			<?php echo $item->p_case ?>
			</td>
		</tr>
		<?php
		$k = 1 - $k;
		endforeach;
	endif;
	?>
	</table>
</div>

	<div>
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form>
